package com.lbn.jfqsc.app.login.register;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.lbn.baseframe.base.BaseActivity;
import com.lbn.baseframe.ui.NAppbar;
import com.lbn.baseframe.utils.EasyToast;
import com.lbn.jfqsc.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RegisterActivity extends BaseActivity<RegisterPresenter> implements IRegister {

    @BindView(R.id.phone)
    EditText phone;
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.confirm_password)
    EditText confirmPassword;
    @BindView(R.id.user_name)
    EditText userName;
    @BindView(R.id.register)
    Button register;
    @BindView(R.id.select_role)
    RadioGroup selectRole;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
        setAppbar(new NAppbar(this));
        appbar.openBack();
        appbar.setTitle("注册");
    }

    public static void startActivity(Context context) {
        context.startActivity(new Intent(context, RegisterActivity.class));
    }


    @Override
    public RegisterPresenter createPresenter() {
        return new RegisterPresenter();
    }


    @Override
    public void onPresenterCreated() {
        super.onPresenterCreated();

    }

    @OnClick(R.id.register)
    public void onClick() {
        mPresenter.register(getPhone(),getPassword(),getConfirmPassword(),getUserName(),getType());
    }


    public String getPhone() {
        return phone.getText().toString();
    }

    public String getPassword() {
        return password.getText().toString();
    }

    public String getConfirmPassword() {
        return confirmPassword.getText().toString();
    }

    public String getUserName() {
        return userName.getText().toString();
    }

    public int getType(){

        for(int i = 0 ;i<selectRole.getChildCount();i++){
            RadioButton radioButton = (RadioButton) selectRole.getChildAt(i);
            if(radioButton.isChecked()){
                return i+1;
            }
        }
        return 0;
    }

    @Override
    public void onSucceed() {
        EasyToast.showShort(this,"注册成功");
        finish();
    }
}
